package com.sumainfor.pc.market.service;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.ParamsCommon;
import com.sumainfor.pc.market.dao.TcmktCorporateMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

/**
 * <p>
 * 增加企业客户与房源中间
 * <p>
 *
 * @author: zhoucong
 * @create: 2019-05-30 18:51
 **/
@Service
public class TcmktCorpHousService implements Serializable {

    private ReentrantLock lock = new ReentrantLock(false);

    Logger log = LoggerFactory.getLogger(TcmktCorporateService.class);// 日志

    @Autowired
    TcmktCorporateMapper tcmktCorporateMapper;

    /**
     * <p>
     * 增加企业客户与房源中间表
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    public JsonResult addCorporateHous(Map<String,Object> params){
        JsonResult result = new JsonResult();
        /**
         * 加锁操作
         */
        lock.lock();
        try {
            log.info("增加操作");
            params.put("term", "2");//创建端  1 租客端 2市场部 3 工程部 4运营部 5财务部 6总经办 7发展部
            params.put("fnc",
                    this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
            ParamsCommon.commonInsertParms(params);
            Integer cout = tcmktCorporateMapper.addCorporateHous(params);
            if(cout<=0){
                result.putFailed("保存失败!");
            }else{
                result.putSuccess("保存成功!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//事物回滚
            result.putFailed("服务器繁忙...");
        } finally {
            lock.unlock();
        }
        return result;

    }
}
